from getConfigInfo import GetConfigInfo
from request import Request
from md5 import MD5
from reWtExcel import GetExcelInfo
from log import logger

preissue = GetConfigInfo('env', 'preissue').get_value()
produce = GetConfigInfo('env', 'produce').get_value()
excel_all_list = GetExcelInfo('case.xls', 'Sheet1').get_excel_info()


def run_all():
    """
    取出要请求的内容，拼接后请求request，拿到响应后，经过md5加密
    加密后进行比对，如果一直，就向Excel中result中插入pass
    如果不一致就插入fail
    :return:
    """
    for i in range(len(excel_all_list)):
        method = excel_all_list[i][0]
        path = excel_all_list[i][1]
        payload = excel_all_list[i][2]
        preissue_url = preissue+path
        produce_url = produce+path
        preissue_req = Request(method=method, urls=preissue_url, data=payload).request_all()
        logger.info('preissue_req:{}'.format(preissue_req[0:10]))
        md5_preissue = MD5(preissue_req).md5_str()
        logger.info('md5_preissue:%s' % md5_preissue)
        produce_req = Request(method=method, urls=produce_url, data=payload).request_all()
        logger.info('produce_req:%s' % preissue_req[0:10])
        md5_produce = MD5(produce_req).md5_str()
        logger.info('md5_produce:%s' % md5_produce)
        logger.info('i::{}'.format(i))
        if md5_preissue == md5_produce:
            logger.info('PASS')
            GetExcelInfo('case.xls', 'Sheet1').wt_excel_info(i + 1, 'PASS')
        else:
            logger.info('FAIL')
            GetExcelInfo('case.xls', 'Sheet1').wt_excel_info(i + 1, 'FAIL')


if __name__ == '__main__':
    run_all()
